/**
 * 
 */
package cz.cvut.fit.crhonjar.mi.run.hawera.tree.statement;

import cz.cvut.fit.crhonjar.mi.run.hawera.tree.TreeVisitor;
import cz.cvut.fit.crhonjar.mi.run.hawera.tree.expression.ExpressionTree;

/**
 * @author Jarec
 * 
 */
public class ForTree extends StatementTree {

	private AssignmentTree initAssignment;
	private ExpressionTree condition;
	private AssignmentTree loopAssignment;

	private StatementTree block;

	/**
	 * constructs for tree
	 * 
	 * @param block
	 * @param initialAssignment
	 * @param condition
	 * @param loopAssignment
	 */
	public ForTree(StatementTree block, AssignmentTree initialAssignment,
			ExpressionTree condition, AssignmentTree loopAssignment) {
		if (this.log.isDebugEnabled()) {
			this.log.debug(
					"> ForTree initAssign: {}, condition: {}, loopAssign: "
							+ (loopAssignment != null),
					initialAssignment != null, condition != null);
		}
		if (block == null) {
			final String message = "Cannot create fortree using null block!";
			this.log.error(message);
			throw new NullPointerException(message);
		}
		this.initAssignment = initialAssignment;
		this.loopAssignment = loopAssignment;
		this.condition = condition;
		this.block = block;
		this.log.debug("< ForTree");
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cz.cvut.fit.crhonjar.mi.run.hawera.tree.TreeVisitorAcceptor#accept(cz
	 * .cvut.fit.crhonjar.mi.run.hawera.tree.TreeVisitor)
	 */
	@Override
	public void accept(TreeVisitor visitor) {
		visitor.visitFor(this);

	}

	/**
	 * @return the block
	 */
	public StatementTree getBlock() {
		this.log.debug(">< getBlock");
		return this.block;
	}

	/**
	 * @return the condition
	 */
	public ExpressionTree getCondition() {
		if (this.log.isDebugEnabled()) {
			this.log.debug(">< getCondition exists?: {}",
					this.condition != null);
		}
		return this.condition;
	}

	/**
	 * @return the initAssignment
	 */
	public AssignmentTree getInitAssignment() {
		if (this.log.isDebugEnabled()) {
			this.log.debug(">< getInitialAssignment exists?: {}",
					this.initAssignment != null);
		}
		return this.initAssignment;
	}

	/**
	 * @return the loopAssignment
	 */
	public AssignmentTree getLoopAssignment() {
		if (this.log.isDebugEnabled()) {
			this.log.debug(">< getLoopAssignment exists?: {}",
					this.loopAssignment != null);
		}
		return this.loopAssignment;
	}

}
